From 7d5856d4d541f3ca46c32113265c3e224aa84db7 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 30 Nov 2006 01:36:43 +0000 Subject: [PATCH] Replace sscanf(..., "", ...) with step-by-step lower level code. --- magproto.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/magproto.c b/magproto.c index e48a9d560..df67ee403 100644 --- a/magproto.c +++ b/magproto.c @@ -969,11 +969,20 @@ mag_rteparse(char *rtemsg) /* Explorist has a route name here */ if (explorist) { - char rten[1024]; - int n2; - sscanf(rtemsg + n, ",%[^,]%n", rten, &n2); - n += n2; - rte_name = xstrdup(rten); + char *ca, *ce; + + ca = rtemsg + n; + is_fatal(*ca++ != ',', MYNAME ": Wrong formated line!"); + + ce = strchr(ca, ','); + is_fatal(ce == NULL, MYNAME ": Wrong formated line!"); + + if (ca == ce) + xasprintf(&rte_name, "Route%d", rtenum); + else + rte_name = xstrndup(ca, ce - ca); + + n += ((ce - ca) + 1); } #endif -- 2.30.2